package com.lx.user.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lx.bean.Result;
import com.lx.bilibili.entity.Relationship;
import com.lx.bilibili.entity.User;
import com.lx.user.dao.RelationshipMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lx
 * @since 2025-03-26
 */
@RestController
@RequestMapping("/relationship")
public class RelationshipController {

    @Autowired
    RelationshipMapper relationshipMapper;

    @RequestMapping("getrelationshipById")
    public Result getRelationshipById(int id) {
        if (relationshipMapper.getRelationshipById(id).size() > 0){
            return new Result(1, "查询成功", relationshipMapper.getRelationshipById(id));
        }else{
            return new Result(0, "暂无信息", null);
        }

    }

    @RequestMapping("saveRelationship")
    public void saveRelationship(int myid, int uid) {
        LambdaQueryWrapper<Relationship> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Relationship::getMyid, myid);
        lqw.eq(Relationship::getUid, uid);
        if (relationshipMapper.selectList(lqw).size() == 0){
            Relationship relationship1 = new Relationship();
            relationship1.setMyid(myid);
            relationship1.setUid(uid);
            relationshipMapper.insert(relationship1);

            Relationship relationship2 = new Relationship();
            relationship2.setMyid(uid);
            relationship2.setUid(myid);
            relationshipMapper.insert(relationship2);
        }
    }
}
